package 反射.动态代理;

import java.lang.reflect.Proxy;

/**
 * 动态代理
 */
public class DynamicProxyMain {

	static void consumer(Interface inter) {
		inter.doSomeThing();
		inter.somethingElse("bonobo");
	}

	public static void main(String[] args) {
		// 常规的静态代理
		RealObject realObject = new RealObject();
		consumer(new StaticProxy(realObject));
		System.out.println("----------------------分割线------------------------------");
		//	 动态代理
		Interface dynamicInterface = (Interface) Proxy.newProxyInstance(
				Interface.class.getClassLoader(),
				new Class[]{Interface.class},
				new DynamicProxyHandler(realObject));
		consumer(dynamicInterface);
	}
}
